package com.lzw.breezeNovel.WebAdmin.controller;


import com.lzw.breezeNovel.WebAdmin.service.CategroyService;
import com.lzw.breezeNovel.WebAdmin.vo.CategoryVo;
import com.lzw.breezeNovel.common.result.Result;
import com.lzw.breezeNovel.model.entity.pojo.Category;
import com.lzw.breezeNovel.model.entity.query.PaginationResultQuery;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分类的控制器
 */
@RestController
@RequestMapping("/admin/category")
@SuppressWarnings("all")
public class CategroyController {

    /**
     * 注入service
     */
    @Resource
    private CategroyService categroyService;


    /**
     * 新增分类
     */
    @PostMapping("/addCategory")
    public Result addCategroy(@RequestBody Category categroy) {
        categroyService.addCategroys(categroy);
        return Result.ok();
    }

    /**
     * 分页获取所有的分类
     */
    @GetMapping("/getAllCategory")
    public Result<PaginationResultQuery<CategoryVo>> getAllCategory(@RequestParam Integer page, @RequestParam Integer pageSize) {
        PaginationResultQuery<CategoryVo> ca = categroyService.getAllCategory(page, pageSize);
        return Result.ok(ca);
    }
    /**
     * 编辑分类
     */
    @PostMapping("/updateCategory")
    public Result editCategory(@RequestBody Category categroy) {
        categroyService.updateCategory(categroy);
        return Result.ok();
    }

    /**
     * 删除分类
     */
    @DeleteMapping("/deleteCategory/{id}")
    public Result deleteCategory(@PathVariable("id") Integer id) {
        categroyService.deleteCategoryById(id);
        return Result.ok();
    }
    /**
     * 批量删除
     */
    @DeleteMapping("/deleteCategoryBatch/{ids}")
    public Result deleteCategory(@PathVariable("ids") Integer[] ids) {
        categroyService.deleteCategoryByIds(ids);
        return Result.ok();
    }

    /**
     * 获取所有的分类
     */
    @GetMapping("/getCategoryList")
    public Result<List<CategoryVo>> getAllCategorys() {
        List<CategoryVo> categoryVo =  categroyService.getAllCategorys();
        return Result.ok(categoryVo);
    }

}
